#!ruby
require 'pp'
require 'yaml'

allPrice = File.open('price.yaml') { |is|    YAML::load(is) }
allFh = File.open('fh.yaml') { |is|    YAML::load(is) }

allNumber = allPrice.keys & allFh.keys
top = Hash.new

allNumber.each do |number|
    next if allPrice[number][1] == 0
    fh = 0
    allFh[number].each do |i|
        next if i[0]!~ /2008/
        fh += i[1]
    end
    if fh == 0
            allFh[number].each do |i|
        next if i[0]!~ /2007/
        fh += i[1]
        end
    end
    years = 10*allPrice[number][1]/fh
    next if years > 25
    top[number] = years
end
t = top.sort{|a,b| a[1] <=>b[1]}
t.each{|tt| 
    printf "\n%7d %8s %8.3f %f %f",tt[0],allPrice[tt[0]][0],allPrice[tt[0]][1],tt[1],1/tt[1]
}
print "\n"
t.each{|tt| 
    print "\n",tt[0],' ',allPrice[tt[0]][0],' ',allPrice[tt[0]][1],' ',tt[1],"\n"
    pp allFh[tt[0]]
}

gets






